package com.example.backend.controller;

import com.example.backend.Utils.WeatherUtil;
import com.example.backend.controller.vo.WeatherVo;
import com.example.backend.model.ResBean;
import com.example.backend.model.WeatherData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping(produces = "application/json;charset=UTF-8")
public class UtilController {
    private WeatherUtil weatherUtil;

    @Autowired
    public UtilController(WeatherUtil weatherUtil) {
        this.weatherUtil = weatherUtil;
    }

    /**
     * 获取城市的天气信息
     */
    @GetMapping("/weather")
    public ResBean getWeather(@RequestParam String city) {
        WeatherData weatherInfo = weatherUtil.getWeather(city);
        //System.out.println(weatherInfo);
        return new ResBean(weatherInfo);
    }

}
